package com.smallchangesys;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class app {

    //1.菜单架构
    boolean loop = true;
    Scanner myscanner = new Scanner(System.in);

    //2.明细
    String detail = "\n----------------零钱通明细----------------";

    //3.收入
    String in_source = "";
    double money = 0;
    double balance = 0;

    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd hh-mm-ss");
    //初始化时间格式

    //4.支出
    double cost = 0;
    String name = "";

    //5.退出
    String type = "";


    public void mainmenu() {

        do {
            System.out.println("----------------零钱通菜单----------------");
            System.out.println("\t\t\t\t1零钱通明细");
            System.out.println("\t\t\t\t2收益入账");
            System.out.println("\t\t\t\t3消费");
            System.out.println("\t\t\t\t4退出");

            System.out.println("请选择:");
            int choice = myscanner.nextInt();

            switch (choice) {
                case 1:
                    this.details();
                    break;
                case 2:
                    this.income();
                    break;
                case 3:
                    this.outcome();
                    break;
                case 4:
                    this.exit();
                    break;
            }

        } while (loop);
    }

    public void details() {
        System.out.println(detail);
    }

    public void income() {
        System.out.println("请输入:");
        money = myscanner.nextDouble();
        balance += money;

        if (money > 0) {
            detail += "\n" + "收益入账" + "\t" + money + "\t" + sdf.format(date) + "\t" + "余额" + balance ;
            //注意换行
        } else {
            System.out.println("输入有误，请重新输入");
        }
    }

    public void outcome() {
        System.out.println("请输入:");
        cost = myscanner.nextDouble();
        System.out.println("请输入消费项目");
        name = myscanner.next();
        balance -= cost;

        if (cost <= balance) {
            detail += "\n" + name + "\t-" + cost + "\t" + sdf.format(date) + "\t" + "余额" + balance ;
            //注意换行
        } else {
            System.out.println("输入有误，请重新输入");
        }
    }

    public void exit(){
        while(true){
            System.out.println("是否退出?y/n");
            type = myscanner.next();
            if(type.equals("y")){
                loop = false;
                break;
            } else if (type.equals("n")){
                break;
            }

        }
    }


}
